<?php

namespace common\models;

use Yii;
use yii\db\ActiveRecord;

/**
 * This is the model class for table "mt_setting".
 *
 * @property integer $id
 * @property string $type
 * @property string $name
 * @property string $key
 * @property string $value
 */
class Setting extends ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'tb_setting';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['key'], 'required'],
            [['value'], 'string'],
            [['type'], 'string', 'max' => 30],
            [['name'], 'string', 'max' => 100],
            [['key'], 'string', 'max' => 50],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'type' => 'Type',
            'name' => 'Name',
            'key' => 'Key',
            'value' => 'Value',
        ];
    }



    /**
     * 获取系统配置
     * @return array
     */
    public static function getSetting()
    {
        $settingArray = array();

        $setting = self::find()->all();

        if (empty($setting))
        {
            return $settingArray;
        }
        foreach ($setting as $set)
        {
            $settingArray[$set['key']] = $set['value'];
        }
        return $settingArray;
    }
}
